class AdminController < ApplicationController
  skip_before_filter :authoriz
  # just display the form and wait for user to
  # enter a name and password
  
  def login
    if request.post?
      user = User.authenticate(params[:email], params[:password])
      if user
        if user.user_status_id != 1
          session[:user_id] = user.id
          # redirect_to(:action => "index")
          if user.user_tipe_id == 1
            redirect_to :controller => 'pendinghorses', :action => 'index'
          else
            redirect_to :controller => 'horses', :action => 'index'  
          end     
        else
          flash[:notice] = "Usuario bloqueado"
          redirect_to :controller => 'horses', :action => 'index'  
        end
      end
    else
      flash.now[:notice] = "<div class='invisible'>Invalid user/password combination</div>"
    end
  end
  
  def logout
    session[:user_id] = nil
    flash[:notice] = "<div class='invisible'>Logged out</div>"
    redirect_to(:controller => 'public', :action => "index")
  end
  
  
  def index
  end
  protected
  def authoriz
    
  end
end
